import bge

# This script is used for object selection with the left mouse button. It will put the selected object
# in bge.selModel, so you can use this for various purposes. The selected model is highlighted with a 
# bounding cube. 

scene = bge.logic.getCurrentScene()
controller = bge.logic.getCurrentController() 
owner = controller.owner

lmb = controller.sensors["LMB"]
mouseOver = controller.sensors["MouseOver"]

if lmb.positive and mouseOver.hitObject != None:
    if mouseOver.hitObject.name[0:3] == "SEL":
        tagID = mouseOver.hitObject.parent.parent
        if tagID.name == bge.selModel:
            bge.selModel = None
            mouseOver.hitObject.visible = False
        else:
            for object in scene.objects:
                if object.name[0:3] == "SEL":
                    object.visible = False
            mouseOver.hitObject.visible = True
            bge.selModel = tagID.name

